import RenderGender from '@/components/RenderGender.vue';
import { AUTH_TYPE_MAP } from '@/const/user'
import { formatTime, renderMaybeNull } from '@/utils';
import type { DataTableProps } from 'naive-ui';
import { NAvatar, NImage, NTag } from 'naive-ui';
import { h } from 'vue';

export const userColumns: DataTableProps['columns'] = [
	{
		title: '头像',
		key: 'avatarUrl',
		align: 'center',
		width: 70,
		render: item => h('div', {
			style: {
				display: 'flex',
				alignItems: 'center',
				flexDirection: 'column',
			}
		}, [
			h(NAvatar, {
				src: item.avatarUrl,
				size: 30,
				round: true,
			}),
			h('div', {
				style: { fontSize: '12px' }
			}, [renderMaybeNull(item.name)])
		])
	},
	{
		title: '性别',
		key: 'gender',
		width: 50,
		render: item => item.gender !== null ? h(RenderGender, { gender: item.gender }) : '--'
	},
	{
		title: '手机号',
		key: 'phone',
		width: 100,
		render: item => renderMaybeNull(item.phone),
	},
	{
		title: '实名认证',
		key: 'realNameAuthStatus',
		width: 80,
		render: item => item.realNameAuthStatus === 1 ? '已认证' : '未认证'
	},
	{
		title: '保证金(冻结/可用)',
		key: 'userMargin',
		width: 120,
		render: item => `${item.userMargin?.frozen||0} / ${item.userMargin?.amount||0}`
	},
	{
		title: '繁殖者认证',
		key: 'breakAuthStatus',
		width: 80,
		render: item => h(NTag, {
			type: item.breedAuthStatus === 1 ? 'success' : 'default',
			size: 'small'
		}, {
			default: () => item.breedAuthStatus === 1 ? '已认证' : '未认证'
		})
	}
]

export const auditUserColumns: DataTableProps['columns'] = [
	{
		title: '姓名',
		key: 'name',
		width: 80,
		render: item => renderMaybeNull(item.name),
	},
	{
		title: '手机号',
		key: 'phone',
		width: 120,
	},
	{
		title: '身份证号码',
		key: 'idcard',
		width: 200,
	},
	{
		title: '认证类型',
		key: 'type',
		width: 100,
		render: (item: any) => AUTH_TYPE_MAP[item.type] || item.type
	},
	{
		title: '身份证（正面）',
		key: 'idcardFront',
		width: 130,
		render: item => h(NImage, {
			src: item.idcardFront,
			height: 50,
			width: 100,
			objectFit: 'contain',
		})
	},
	{
		title: '身份证（反面）',
		key: 'idcardBack',
		width: 130,
		render: item => h(NImage, {
			src: item.idcardBack,
			height: 50,
			width: 100,
			objectFit: 'contain',
		})
	},
	{
		title: '提交时间',
		key: 'city',
		width: 180,
		render: item => formatTime(item.createTime)
	},
]
